import { BasicColumn, FormSchema } from '@/components/Table';
import { dateUtil } from '@/utils/dateUtil';

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'amount',
    label: '充值金额',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'giveAmount',
    label: '赠送金额',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'orders',
    label: '排序',
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'memo',
    label: '备注',
    component: 'InputTextArea',
  },
];
export const couPonColumns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 20,
  },
  {
    title: '优惠券名称',
    dataIndex: 'name',
    width: 80,
  },
  {
    title: '金额',
    dataIndex: 'amount',
    width: 50,
  },
  {
    title: '生效日期',
    dataIndex: 'startDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD');
    },
  },
  {
    title: '失效日期',
    dataIndex: 'endDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD');
    },
  },
];

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '头像',
    dataIndex: 'headUrl',
    width: 50,
  },
  {
    title: '性别',
    dataIndex: 'gender',
    width: 50,
    customRender: ({ text }) => {
      return text == '0' ? '女' : '男';
    },
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 60,
  },
  {
    title: '车牌号',
    dataIndex: 'licenseNo',
    width: 100,
  },
  {
    title: '余额(元)',
    dataIndex: 'balance',
    width: 70,
  },
  {
    title: '积分',
    dataIndex: 'point',
    width: 30,
  },
  {
    title: '分组',
    dataIndex: 'groupsName',
    width: 30,
  },
  {
    title: '注册方式',
    dataIndex: 'regSource',
    width: 70,
    customRender: ({ text }) => {
      return text == '1' ? '小程序' : 'APP';
    },
  },
  {
    title: '累计消费(元)',
    dataIndex: 'balance',
    width: 60,
    customRender: ({ record }) => {
      return parseFloat(record.historyBalance - record.balance).toFixed(2);
    },
  },
  {
    title: '累计充电(度)',
    dataIndex: 'sumPower',
    width: 80,
    customRender: ({ text }) => {
      return parseFloat(text).toFixed(3); // 强制显示三位小数
    },
  },
  {
    title: '电费(元)',
    dataIndex: 'sumPowerMoney',
    width: 80,
    customRender: ({ text }) => {
      return parseFloat(text).toFixed(3); // 强制显示三位小数
    },
  },
  {
    title: '服务费(元)',
    dataIndex: 'sumServiceMoney',
    width: 80,
    customRender: ({ text }) => {
      return parseFloat(text).toFixed(3); // 强制显示三位小数
    },
  },
  {
    title: '停车费(元)',
    dataIndex: 'sumParkMoney',
    width: 80,
    customRender: ({ text }) => {
      return parseFloat(text).toFixed(3); // 强制显示三位小数
    },
  },
  {
    title: '累计充电(度)',
    dataIndex: 'sumChargeTimes',
    width: 80,
  },
  {
    title: '订单总数(个)',
    dataIndex: 'sumChargeTimes',
    width: 80,
  },
  {
    title: '已开票',
    dataIndex: 'sumInvoiceSpendMoney',
    width: 80,
  },
  {
    title: '未开票',
    dataIndex: 'sumNotInvoiceSpendMoney',
    width: 80,
  },
  {
    title: '上次充电',
    dataIndex: 'lastChargeDate',
    width: 160,
    customRender: ({ text }) => {
      return text != null ? dateUtil(text).format('YYYY-MM-DD HH:mm:ss') : '';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 60,
    customRender: ({ text }) => {
      if (text == '0') {
        return '正常';
      } else if (text == '1') {
        return '已冻结';
      }
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'groupsId',
    label: '分组',
    component: 'ApiSelect',
    componentProps: {
      api: '/admin/groups/list',
      treeDefaultExpandAll: false,
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'startTime',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'endTime',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'keyword',
    label: '姓名/手机号',
    component: 'Input',
    labelWidth: 80,
    colProps: {
      span: 6,
    },
  },
  {
    field: 'memberType',
    label: '用户类型',
    component: 'Select',
    componentProps: {
      options: [
        { name: '新用户', id: '0' },
        { name: '老用户', id: '1' },
      ],
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    colProps: {
      span: 5,
    },
  },
];
